<template>
  <div class="shop-bg">
    <div class="top-fixed-btns">
      <el-tooltip content="我的收藏" placement="bottom">
        <el-button @click="showFavorite = true" size="large" circle class="top-btn" type="warning" :icon="Star" />
      </el-tooltip>
      <el-tooltip content="我的订单" placement="bottom">
        <el-button @click="showOrder = true" size="large" circle class="top-btn" type="primary" :icon="Document" />
      </el-tooltip>
      <el-tooltip content="浏览记录" placement="bottom">
        <el-button @click="showBrowsing = true" size="large" circle class="top-btn" type="success" :icon="View" />
      </el-tooltip>
      <el-tooltip content="跳转购物车" placement="bottom">
        <el-button
          @click="goCart"
          size="large"
          circle
          class="top-btn cart-btn"
          type="primary"
          :icon="ShoppingCart"
          style="box-shadow: 0 4px 16px rgba(64,158,255,0.25); border: 2px solid #409eff; background: linear-gradient(90deg, #409eff 60%, #66b1ff 100%); color: #fff;"
        />
      </el-tooltip>
    </div>
    <!-- 收藏列表弹窗 -->
    <el-dialog v-model="showFavorite" title="我的收藏" width="700px" @close="favoriteList = []">
      <el-table :data="favoriteList" style="width:100%" v-loading="loadingFavorite" empty-text="暂无收藏">
        <el-table-column label="图片" width="80">
          <template #default="scope">
            <img :src="fullImg(scope.row.product.cover_image)" style="width:60px;height:60px;object-fit:cover;border-radius:8px;cursor:pointer;" @click="goDetail(scope.row.product.id)" />
          </template>
        </el-table-column>
        <el-table-column prop="product.name" label="商品" min-width="120">
          <template #default="scope">
            <span style="color:#409eff;cursor:pointer;" @click="goDetail(scope.row.product.id)">{{ scope.row.product.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="product.price" label="价格" width="80" />
        <el-table-column prop="timestamp" label="收藏时间" min-width="160">
          <template #default="scope">
            {{ formatTime(scope.row.timestamp) }}
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align:center;margin-top:12px;">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="favoriteTotal"
          :page-size="favoritePageSize"
          :current-page="favoritePage"
          @current-change="handleFavoritePageChange"
          :pager-count="7"
          hide-on-single-page
        />
      </div>
    </el-dialog>
    <!-- 订单列表弹窗 -->
    <el-dialog v-model="showOrder" title="我的订单" width="800px" @close="orderList = []">
      <el-table :data="orderList" style="width:100%" v-loading="loadingOrder" empty-text="暂无订单">
        <el-table-column label="图片" width="80">
          <template #default="scope">
            <img :src="fullImg(scope.row.product.cover_image)" style="width:60px;height:60px;object-fit:cover;border-radius:8px;cursor:pointer;" @click="goDetail(scope.row.product.id)" />
          </template>
        </el-table-column>
        <el-table-column prop="product.name" label="商品" min-width="120">
          <template #default="scope">
            <span style="color:#409eff;cursor:pointer;" @click="goDetail(scope.row.product.id)">{{ scope.row.product.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="product.price" label="单价" width="80" />
        <el-table-column prop="quantity" label="数量" width="60" />
        <el-table-column label="总价" width="100">
          <template #default="scope">
            ￥{{ (scope.row.product.price * scope.row.quantity).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column prop="timestamp" label="下单时间" min-width="160">
          <template #default="scope">
            {{ formatTime(scope.row.timestamp) }}
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align:center;margin-top:12px;">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="orderTotal"
          :page-size="orderPageSize"
          :current-page="orderPage"
          @current-change="handleOrderPageChange"
          :pager-count="7"
          hide-on-single-page
        />
      </div>
    </el-dialog>
    <!-- 浏览记录弹窗 -->
    <el-dialog v-model="showBrowsing" title="浏览记录" width="800px" @close="browsingList = []">
      <el-table :data="browsingList" style="width:100%" v-loading="loadingBrowsing" empty-text="暂无浏览记录">
        <el-table-column label="图片" width="80">
          <template #default="scope">
            <img :src="fullImg(scope.row.product.cover_image)" style="width:60px;height:60px;object-fit:cover;border-radius:8px;cursor:pointer;" @click="goDetail(scope.row.product.id)" />
          </template>
        </el-table-column>
        <el-table-column prop="product.name" label="商品" min-width="120">
          <template #default="scope">
            <span style="color:#409eff;cursor:pointer;" @click="goDetail(scope.row.product.id)">{{ scope.row.product.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="quantity" label="浏览次数" width="80" />
        <el-table-column prop="timestamp" label="最后浏览时间" min-width="160">
          <template #default="scope">
            {{ formatTime(scope.row.timestamp) }}
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align:center;margin-top:12px;">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="browsingTotal"
          :page-size="browsingPageSize"
          :current-page="browsingPage"
          @current-change="handleBrowsingPageChange"
          :pager-count="7"
          hide-on-single-page
        />
      </div>
    </el-dialog>
    <!-- Hero Carousel for Newest Products -->
    <el-carousel v-if="newestProducts.length" height="550px" class="hero-carousel" trigger="click" arrow="always">
      <el-carousel-item v-for="item in newestProducts" :key="item.id">
        <div
          class="carousel-slide"
          :style="{ backgroundImage: `url(${fullImg(item.cover_image)})` }"
          @click="goDetail(item.id)"
        >
          <div class="slide-content">
            <el-tag type="danger" effect="dark" size="large">最新上架</el-tag>
            <h1 class="slide-title">{{ item.name }}</h1>
            <p class="slide-desc">{{ item.short_desc }}</p>
            <el-button type="primary" size="large" round @click.stop="goDetail(item.id)">
              查看详情
            </el-button>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>

    <!-- Fallback Header if no products -->
    <div v-else class="shop-header-fallback">
      <h1>精品商城</h1>
      <p>精选好物，为您的品质生活加分</p>
    </div>

    <!-- Controls: Search and Sort -->
    <div class="shop-controls">
      <el-input
        v-model="searchQuery"
        placeholder="搜索商品..."
        size="large"
        :prefix-icon="Search"
        clearable
        class="search-input"
      />
      <el-select v-model="sortOrder" size="large" placeholder="排序方式">
        <el-option label="默认排序" value="default" />
        <el-option label="价格从低到高" value="price-asc" />
        <el-option label="价格从高到低" value="price-desc" />
      </el-select>
    </div>

    <!-- Product List -->
    <el-row :gutter="32" class="shop-list">
      <el-col
        v-for="item in filteredProducts"
        :key="item.id"
        :xs="24" :sm="12" :md="8" :lg="6"
      >
        <el-card
          class="product-card"
          shadow="hover"
          :body-style="{ padding: '0px' }"
          @click="goDetail(item.id)"
        >
          <div class="img-wrap">
            <img :src="fullImg(item.cover_image)" class="product-img" />
            <div class="actions-overlay">
              <el-button type="primary" :icon="ShoppingCart" circle @click.stop="addToCart(item)" title="加入购物车" />
              <el-button type="info" :icon="View" circle @click.stop="goDetail(item.id)" title="查看详情" />
            </div>
            <div class="discount-tag" v-if="getDiscount(item) > 0">
              -{{ getDiscount(item) }}%
            </div>
          </div>
          <div class="product-info">
            <h3 class="product-title">{{ item.name }}</h3>
            <p class="product-desc">{{ item.short_desc }}</p>
            <div class="product-price-row">
              <span class="price">￥{{ item.price }}</span>
              <span class="original" v-if="getDiscount(item) > 0">￥{{ item.original_price }}</span>
            </div>
            <div class="stock-info">
              <el-progress
                :percentage="getStockPercentage(item.detail?.stock)"
                :status="getStockStatus(item.detail?.stock)"
                :stroke-width="6"
                :show-text="false"
                title="库存水平"
              />
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-empty v-if="!filteredProducts.length && !loadingProducts" description="没有找到匹配的商品" />
    <div v-if="productTotal >= 8" style="text-align:center;margin:24px 0;">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="productTotal"
        :page-size="productPageSize"
        :current-page="productPage"
        @current-change="handleProductPageChange"
        :pager-count="7"
        hide-on-single-page
      />
    </div>
    <!-- 热门推荐分页条和列表 -->
    <el-card class="hotlist-card" v-loading="loadingHot" style="margin-bottom:32px; margin-top: 12px;">
      <div class="hotlist-title">
        <el-icon style="color:#f56c6c"><i class="el-icon-fire"></i></el-icon>
        热门推荐
      </div>
      <el-row :gutter="24">
        <el-col v-for="(item, idx) in filteredHotList" :key="item.id" :xs="24" :sm="12" :md="8" :lg="6">
          <el-card class="hotlist-item" shadow="hover" @click="$router.push(`/shop/${item.id}`)">
            <img :src="fullImg(item.cover_image)" class="hotlist-img" />
            <div class="hotlist-info">
              <div class="hotlist-rank" :class="{'top3': idx<3}">NO.{{ idx+1 }}</div>
              <div class="hotlist-name">{{ item.name }}</div>
              <div class="hotlist-price">￥{{ item.price }}</div>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-empty v-if="!filteredHotList.length && !loadingHot" description="暂无热门商品" />
      <div style="text-align:center;margin:24px 0;">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="hotTotal"
          :page-size="hotPageSize"
          :current-page="hotPage"
          @current-change="handleHotPageChange"
          :pager-count="7"
          hide-on-single-page
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted, computed, watch } from 'vue'
import { useRouter } from 'vue-router'
import request from '@/utils/request'
import { Search, ShoppingCart, View, Star, Document } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { useUserStore } from '../stores/user'

const allProducts = ref([])
const productTotal = ref(0)
const productPage = ref(1)
const productPageSize = ref(12)
const loadingProducts = ref(false)
const router = useRouter()
const searchQuery = ref('')
const sortOrder = ref('default')
const showFavorite = ref(false)
const showOrder = ref(false)
const showBrowsing = ref(false)
const favoriteList = ref([])
const orderList = ref([])
const browsingList = ref([])
const favoritePage = ref(1)
const favoritePageSize = ref(10)
const favoriteTotal = ref(0)
const orderPage = ref(1)
const orderPageSize = ref(10)
const orderTotal = ref(0)
const browsingPage = ref(1)
const browsingPageSize = ref(10)
const browsingTotal = ref(0)
const loadingFavorite = ref(false)
const loadingOrder = ref(false)
const loadingBrowsing = ref(false)
const userStore = useUserStore()
const hotList = ref([])
const hotTotal = ref(0)
const hotPage = ref(1)
const hotPageSize = ref(8)
const loadingHot = ref(false)
const selectedProductId = ref(null)
const cartList = ref([])
const lastAddTimestamps = ref({}) // { [goodsid]: timestamp }

// Computed property for newest products for the carousel
const newestProducts = computed(() => {
  return [...allProducts.value]
    .filter(p => p.detail && typeof p.detail.stock === 'number' && p.detail.stock > 0)
    .sort((a, b) => b.id - a.id)
    .slice(0, 4)
})

// Computed property for filtering and sorting
const filteredProducts = computed(() => {
  let products = [...allProducts.value]

  // 只展示有库存的商品
  products = products.filter(p => p.detail && typeof p.detail.stock === 'number' && p.detail.stock > 0)

  if (searchQuery.value) {
    const query = searchQuery.value.toLowerCase()
    products = products.filter(p =>
      p.name.toLowerCase().includes(query) ||
      p.short_desc.toLowerCase().includes(query)
    )
  }

  if (sortOrder.value === 'price-asc') {
    products.sort((a, b) => parseFloat(a.price) - parseFloat(b.price))
  } else if (sortOrder.value === 'price-desc') {
    products.sort((a, b) => parseFloat(b.price) - parseFloat(a.price))
  }
  return products
})

// 搜索时拉取所有商品
watch(searchQuery, async (val) => {
  if (val && allProducts.value.length < productTotal.value) {
    // 如果有搜索词且当前allProducts未加载全量，则拉取全部
    const res = await request.get('shop/products/', {
      params: { page: 1, page_size: productTotal.value || 9999 }
    })
    allProducts.value = res.results || []
    productTotal.value = res.count || allProducts.value.length
  }
});

const filteredHotList = computed(() => {
  return (hotList.value || []).filter(item => item.detail && typeof item.detail.stock === 'number' && item.detail.stock > 0)
})

const goDetail = id => router.push(`/shop/${id}`)
const fullImg = url => url.startsWith('http') ? url : `http://127.0.0.1:8000/media${url}`

const fetchCartList = async () => {
  const res = await request.get('/shop/cart/', {
    params: { userid: userStore.userid }
  })
  cartList.value = res.carts || []
}

const addToCart = async (item) => {
  // 1. 判断购物车中是否已存在该商品
  const exists = cartList.value.some(cart => cart.product.id === item.id)
  if (exists) {
    ElMessage.info('该商品已在购物车中')
    return
  }
  // 2. 3秒内重复点击同一商品提示
  const now = Date.now()
  if (lastAddTimestamps.value[item.id] && now - lastAddTimestamps.value[item.id] < 3000) {
    ElMessage.warning('3秒内请勿重复添加该商品')
    return
  }
  lastAddTimestamps.value[item.id] = now
  try {
    const res = await request.post('/shop/cart/', {
      userid: userStore.userid,
      goodsid: item.id,
      quantity: 1
    })
    if (res.code === 200) {
      ElMessage.success(`${item.name} 已添加到购物车`)
      await fetchCartList()
    } else {
      ElMessage.error(res.msg || '添加失败')
    }
  } catch (e) {
    ElMessage.error('网络异常，添加失败')
  }
}

// Data Visualization Helpers
const getDiscount = (item) => {
  if (!item.original_price || !item.price || item.original_price <= item.price) return 0
  return Math.round(((item.original_price - item.price) / item.original_price) * 100)
}

const getStockPercentage = (stock = 0) => {
  const maxStock = 200 // Assume max stock is 200 for visualization
  return Math.min((stock / maxStock) * 100, 100)
}

const getStockStatus = (stock = 0) => {
  if (stock > 100) return 'success'
  if (stock > 20) return 'warning'
  return 'exception'
}

const fetchProducts = async (page = 1) => {
  loadingProducts.value = true
  try {
    const res = await request.get('shop/products/', {
      params: { page, page_size: productPageSize.value }
    })
    console.log('接口原始响应', res)
    allProducts.value = res.results || []
    productTotal.value = res.count || 0
  } catch (e) {
    console.error('商品数据加载失败', e)
    allProducts.value = []
    productTotal.value = 0
    ElMessage.error('商品数据加载失败')
  }
  loadingProducts.value = false
}

const fetchFavorite = async (page = 1) => {
  loadingFavorite.value = true
  const res = await request.get('/shop/favorite/list/', {
    params: { userid: userStore.userid, page, page_size: favoritePageSize.value }
  })
  favoriteList.value = res.data && res.data.favorites ? res.data.favorites : (res.favorites || [])
  favoriteTotal.value = res.data && res.data.total ? res.data.total : (res.total || 0)
  loadingFavorite.value = false
}
const fetchOrder = async (page = 1) => {
  loadingOrder.value = true
  const res = await request.get('/shop/order/list/', {
    params: { userid: userStore.userid, page, page_size: orderPageSize.value }
  })
  orderList.value = res.data && res.data.orders ? res.data.orders : (res.orders || [])
  orderTotal.value = res.data && res.data.total ? res.data.total : (res.total || 0)
  loadingOrder.value = false
}
const fetchBrowsing = async (page = 1) => {
  loadingBrowsing.value = true
  const res = await request.get('/shop/browse/list/', {
    params: { userid: userStore.userid, page, page_size: browsingPageSize.value }
  })
  browsingList.value = res.data && res.data.browsings ? res.data.browsings : (res.browsings || [])
  browsingTotal.value = res.data && res.data.total ? res.data.total : (res.total || 0)
  loadingBrowsing.value = false
}

const fetchHotList = async (page = 1) => {
  loadingHot.value = true
  try {
    const res = await request.get('shop/hotlist/', {
      params: { page, page_size: hotPageSize.value }
    })
    if (res && Array.isArray(res.nlist)) {
      hotList.value = res.nlist
      hotTotal.value = res.total || 0
    } else {
      hotList.value = []
      hotTotal.value = 0
      // 可选：弹窗或提示"商品数据加载失败"
    }
  } finally {
    loadingHot.value = false
  }
}

function formatTime(time) {
  if (!time) return ''
  const d = new Date(time)
  return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')} ${String(d.getHours()).padStart(2,'0')}:${String(d.getMinutes()).padStart(2,'0')}`
}

watch(showFavorite, v => v && fetchFavorite(favoritePage.value))
watch(showOrder, v => v && fetchOrder(orderPage.value))
watch(showBrowsing, v => v && fetchBrowsing(browsingPage.value))

function handleFavoritePageChange(page) {
  favoritePage.value = page
  fetchFavorite(page)
}
function handleOrderPageChange(page) {
  orderPage.value = page
  fetchOrder(page)
}
function handleBrowsingPageChange(page) {
  browsingPage.value = page
  fetchBrowsing(page)
}

function handleProductPageChange(page) {
  productPage.value = page
  fetchProducts(page)
}
function handleHotPageChange(page) {
  hotPage.value = page
  fetchHotList(page)
}

onMounted(async () => {
  await fetchProducts(productPage.value)
  await fetchHotList(hotPage.value)
  await fetchCartList()
})

// 记录行为
request.get('/shop/recommend/', {
  params: {
    action: 'collect',
    userid: 1001,
    goodsid: 2003,
    count: 1,
    action_type: '购买'
  }
})

// 获取相似用户
request.get('/shop/recommend/', {
  params: {
    action: 'similarity',
    userid: 1001
  }
})

// 获取推荐商品
request.get('/shop/recommend/', {
  params: {
    action: 'recommend',
    userid: 1001,
    num: 5
  }
})

function goCart() {
  router.push('/cart')
}
</script>

<style scoped>
.shop-bg {
  background-color: #f4f6f8;
  min-height: 100vh;
}

.top-fixed-btns {
  position: fixed;
  top: 24px;
  right: 32px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: flex-end;
}

.top-btn {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: box-shadow 0.2s, background 0.2s;
}

.top-btn:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.16);
  filter: brightness(1.08);
}

@media (max-width: 600px) {
  .top-fixed-btns {
    top: 12px;
    right: 8px;
    gap: 10px;
  }
  .top-btn {
    width: 38px !important;
    height: 38px !important;
    font-size: 18px !important;
  }
}

/* --- Hero Carousel Styles --- */
.hero-carousel {
  width: 100%;
  margin-bottom: -40px; /* Overlap with controls */
}

.carousel-slide {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
}

.carousel-slide::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 50%);
  z-index: 1;
}

.slide-content {
  position: relative;
  z-index: 2;
  color: white;
  padding: 20px;
  max-width: 700px;
  transform: translateY(20px);
  transition: transform 0.5s ease;
}

.carousel-slide:hover .slide-content {
    transform: translateY(0);
}

.slide-title {
  font-size: 3.5rem;
  font-weight: 800;
  text-shadow: 0 4px 15px rgba(0,0,0,0.5);
  margin: 15px 0;
  line-height: 1.2;
}

.slide-desc {
  font-size: 1.2rem;
  color: rgba(255,255,255,0.9);
  margin-bottom: 30px;
  text-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

.slide-content .el-button {
  --el-button-font-weight: 600;
  padding: 18px 35px;
  font-size: 1rem;
}

.shop-header-fallback {
  text-align: center;
  padding: 60px 20px 40px;
  background: white;
  margin-bottom: 30px;
}

/* Customizing Carousel Indicators */
.hero-carousel :deep(.el-carousel__indicator .el-carousel__button) {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid white;
  background-color: transparent;
  opacity: 0.6;
}

.hero-carousel :deep(.el-carousel__indicator.is-active .el-carousel__button) {
  background-color: #ffffff;
  opacity: 1;
}
/* --- End Header Styles --- */

.shop-controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  max-width: 900px;
  margin: 0 auto 40px;
  padding: 0 20px;
  position: relative;
  z-index: 3;
}
.search-input {
  max-width: 500px;
}
.search-input .el-input__wrapper, .shop-controls .el-select .el-input__wrapper {
  border-radius: 50px !important;
  background-color: white;
  box-shadow: 0 5px 20px -5px rgba(0,0,0,0.08);
  border: none;
  height: 50px;
}

.shop-list {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px 40px;
}
.product-card {
  border-radius: 12px;
  border: 1px solid #e5e9f2;
  transition: all 0.3s ease;
  cursor: pointer;
  overflow: hidden;
}
.product-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 10px 30px -10px rgba(0,0,0,0.15);
}
.img-wrap {
  position: relative;
  width: 100%;
  height: 240px;
  overflow: hidden;
}
.product-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.product-card:hover .product-img {
  transform: scale(1.1);
}
.actions-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.product-card:hover .actions-overlay {
  opacity: 1;
}
.discount-tag {
  position: absolute;
  top: 10px;
  left: 10px;
  background-color: #f56c6c;
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
}
.product-info {
  padding: 16px;
}
.product-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #2d3748;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
}
.product-desc {
  font-size: 0.9rem;
  color: #a0aec0;
  margin-bottom: 12px;
  height: 2.7rem;
  overflow: hidden;
}
.product-price-row {
  display: flex;
  align-items: baseline;
  margin-bottom: 12px;
}
.price {
  font-size: 1.4rem;
  color: #dd6b20;
  font-weight: 700;
  margin-right: 8px;
}
.original {
  font-size: 0.9rem;
  color: #a0aec0;
  text-decoration: line-through;
}
.stock-info {
  margin-top: 10px;
}

.hotlist-card {
  border-radius: 18px;
  box-shadow: 0 4px 32px rgba(255,87,34,0.10);
  padding: 28px 28px 18px 28px;
  background: linear-gradient(135deg, #fff7f0 0%, #f8fafc 100%);
}
.hotlist-title {
  font-size: 1.6rem;
  font-weight: bold;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: 2px;
}
.hotlist-item {
  margin-bottom: 18px;
  cursor: pointer;
  border-radius: 14px;
  transition: box-shadow 0.2s;
  background: #fff;
}
.hotlist-item:hover {
  box-shadow: 0 8px 32px #f56c6c22;
  transform: translateY(-2px) scale(1.03);
}
.hotlist-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 12px;
  background: #f8f8f8;
}
.hotlist-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.hotlist-rank {
  font-size: 1.2rem;
  font-weight: bold;
  color: #f56c6c;
}
.hotlist-rank.top3 {
  color: #ff9800;
  font-size: 1.3rem;
}
.hotlist-name {
  font-size: 1.15rem;
  font-weight: 500;
  color: #222;
}
.hotlist-price {
  color: #f56c6c;
  font-size: 1.15rem;
  font-weight: bold;
}
.cart-btn {
  animation: cart-pop 0.6s;
  border-radius: 50% !important;
  font-size: 22px !important;
  background: linear-gradient(90deg, #409eff 60%, #66b1ff 100%) !important;
  color: #fff !important;
  border: 2px solid #409eff !important;
  box-shadow: 0 4px 16px rgba(64,158,255,0.25) !important;
  transition: box-shadow 0.2s, background 0.2s;
}
.cart-btn:hover {
  box-shadow: 0 8px 32px rgba(64,158,255,0.35) !important;
  filter: brightness(1.08);
}
@keyframes cart-pop {
  0% { transform: scale(0.7); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
</style>